var RecentCounter = function() {
  this.val = []
};

/** 
* @param {number} t
* @return {number}
*/
RecentCounter.prototype.ping = function(t) {
  this.val.push(t)
  while( this.val[0] < t-3000){
    this.val.shift()
  }
  return this.val.length
};

var obj = new RecentCounter()
console.log(
  obj.ping(1),
  obj.ping(100),
  obj.ping(3001),
  obj.ping(3002)
);